package com.rentcars.controller;

import com.github.pagehelper.PageInfo;
import com.rentcars.entity.Cars;
import com.rentcars.entity.Result;
import com.rentcars.service.CarShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zezhao
 * 新车审核
 */
@RestController
@RequestMapping("/checkcars")
public class CheckCarController {
    @Autowired
    private CarShareService carShareService;

    //新车入册
    @RequestMapping("")
    public ModelAndView toAdd(){//左侧跳转页面
        return new ModelAndView("check-list");
    }

    @RequestMapping("/query")
    public PageInfo<Cars> query(@RequestParam(required = false) String carcode,
                                     @RequestParam(required = false) String mobile,
                                     @RequestParam(required = false) Integer pageNo,
                                     @RequestParam(required = false) Integer pageSize){

        //查询所有数据
        PageInfo<Cars> carsPageInfo = carShareService.selectAll(carcode, mobile, pageNo, pageSize);
        return carsPageInfo;
    }


    //按id查询
    @RequestMapping("/edit")
    public ModelAndView edit(String carid){
        Cars cars=carShareService.selectByPrimaryKey(carid);

        System.out.println(cars);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("cars",cars);
        modelAndView.setViewName("check-edit");
        return modelAndView;
    }

    //修改
    @RequestMapping("/upEdit")
    public Result upEdit(Cars cars){

        carShareService.updateByPrimaryKeySelective(cars);
        return new Result();
    }

}
